package com.qingke.easyjava.besuper2.command.impi;

import java.util.List;

import com.qingke.easyjava.besuper2.QuestionDao;
import com.qingke.easyjava.besuper2.command.PlayerCommand;
import com.qingke.easyjava.besuper2.pojo.Player;
import com.qingke.easyjava.besuper2.pojo.Question;
import com.qingke.easyjava.utils.QingkeConsole;

public class AskCommand extends PlayerCommand {

	public AskCommand(Player playerProfile) {
		super(playerProfile);
	}

	@Override
	public void execute() {
		String content = QingkeConsole.askUserInputString("Please enter your question");
		int credit = QingkeConsole.askUserInputInt("Please eneter the credit");
		
		int score = playerProfile.getScore();
		
		if(score < credit) {
			QingkeConsole.println("Insufficient credit! You have only" + score + "credit");
			credit = score;
		}
		
		Question question = new Question(content, playerProfile.getId(), credit);
		QuestionDao qd = new QuestionDao();
		qd.upsertQuestion(question);
		
		List<Question> questions = qd.getQuestionsFrom(playerProfile.getId());
		playerProfile.setQuestions(questions);
		
		QingkeConsole.println("Your question has benn recored!");
	}

}
